package com.zhaopin.servlet;

import com.alibaba.fastjson.JSON;
import com.zhaopin.dao.QDao;
import com.zhaopin.vo.UserVo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(urlPatterns = "/api/v1/user/zhaopin")
public class UserServlet extends HttpServlet {
    QDao qDao=new QDao();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("application/json;charset=utf-8");
        PrintWriter out=resp.getWriter();

        String action=req.getParameter("action");
        if ("getAll".equals(action)) {
            List<UserVo> userVo=qDao.getUser();
            out.print(JSON.toJSONString(userVo));
        }


        out.close();

    }
}
